﻿using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using Bling.DSL;
using Bling.WPF;

namespace Bling.Tutorial {
  public class Shaders : Canvas {
    public Shaders() {
      CanvasBl canvas = this;
      var image = new ImageBl(canvas) { 
        Height = 400,
        Source = Properties.Resources.Autumn, CenterPosition = canvas.CenterSize 
      };
      PointBl At = new PointBl(0, 0);
      At = new ButtonBl(canvas) {
        LeftTop = At, Content = "None",
        Click = () => image.Effect.Custom = (input, uv) => input[uv]
      }.RightTop;

      At = new ButtonBl(canvas) {
        LeftTop = At, Content = "FlipH",
        Click = () => image.Effect.Custom = (input, uv) => input[new PointBl(1 - uv.X, uv.Y)]
      }.RightTop;

      At = new ButtonBl(canvas) {
        LeftTop = At, Content = "FlipH",
        Click = () => image.Effect.Custom = (input, uv) => input[new PointBl(uv.X, 1 - uv.Y)]
      }.RightTop;


      ThumbBl thumb = new ThumbBl(canvas) {
        CenterPosition = canvas.CenterSize, ZIndex = 1, CanDrag = true, Background = Brushes.Red,
      };
      LabelSliderBl slider = new LabelSliderBl(canvas) {
        Minimum = 1, Maximum = 10, Value = 5,
        Width = image.Width, LeftBottom = image.LeftTop, LabelName = "Light", Visibility = false,
      };
      At = new ButtonBl(canvas) {
        LeftTop = At, Content = "Lense",
        Click = () => image.Effect.Custom = (input, uv) => {
          slider.Visibility = true;
          PointBl v = ((uv * image.Size) - (thumb - image.LeftTop));
          DoubleBl l = (v.Length / 100);
          l = l.Pow(slider.Value);
          l = (l >= 1).Condition(0, l);
          var n = v.Normal;
          var clr = input[uv + (l * n * .1)];
          return l.Lerp(clr, Colors.Gray);
        }
      }.RightTop;
    }
  }
}
